package cn.itsource._05topic;

import cn.itsource.utils.RabbitMQUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

/**
 * @Author: CTL
 * @Description: 消息生产者，主题
 * @DateTime: 2023年06月13日 18:40
 */

public class ProducerFanout {
    /**
     * @Description 交换机名称
     */
    public static final String EXCHANGE_DIRECT = "exchange_topic";

    /**
    * @description: 消息生产者，主题模式
    * @author: CTL
    * @date: 2023/6/13 19:01
    * @param
    * @return
    */
    public static void main(String[] args) throws Exception {
        // 1.获取连接
        Channel channel = RabbitMQUtil.getchannel();
        // 2.创建交换机
        channel.exchangeDeclare(EXCHANGE_DIRECT, BuiltinExchangeType.TOPIC);
        // 3.发送消息
        for (int i = 0; i < 10; i++) {
            channel.basicPublish(EXCHANGE_DIRECT, "test.mq", null, ("这是一个fanout消息" + i).getBytes());
        }
        System.out.println("消息发送完毕");
    }
}
